//
//  ModifyNickNameVC.m
//  MyProject
//
//  Created by jiaming yan on 2018/3/30.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "ModifyNickNameVC.h"

@interface ModifyNickNameVC ()
@property (weak, nonatomic) IBOutlet UITextField *nickNameTextField;

@end

@implementation ModifyNickNameVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"修改昵称";
    self.nickNameTextField.text = self.strName;
    [self rightButton];
}
-(void)rightButton{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 100, 44);
    [backBtn setTitle:@"保存" forState:UIControlStateNormal];
    [backBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
//    [backBtn setImage:IMAGE(@"ic_tip_black") forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(finishClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    negativeSpacer.width = -20;
    self.navigationItem.rightBarButtonItems = @[negativeSpacer,backItem];
    
    if (IOS11Later) {
        backBtn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
    }
}
- (IBAction)finishClick:(id)sender {
    if (!self.nickNameTextField.text || self.nickNameTextField.text.length == 0) {
        [CommonUtils showToast:@"请输入昵称"];
        return;
    }
    if (self.nickNameTextField.text.length > 10) {
        [CommonUtils showToast:@"昵称不能超过10个字"];
        return;
    }
    if (self.modifyNickName) {
        self.modifyNickName(self.nickNameTextField.text);
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
